export default {
	namespaced: true,
	state: {
		iframeList: []
	},
	mutations: {
		setIframeList(state, route) {
			state.iframeList = []
			state.iframeList.push(route)
		},
		pushIframeList(state, route) {
			let target = state.iframeList.find((item) => item.path === route.path)
			if (!target) {
				state.iframeList.push(route)
			}
		},
		removeIframeList(state, route) {
			state.iframeList.forEach((item, index) => {
				if (item.path === route.path) {
					state.iframeList.splice(index, 1)
				}
			})
		},
		refreshIframe(state, route) {
			state.iframeList.forEach((item) => {
				if (item.path == route.path) {
					var url = route.meta.url;
					item.meta.url = '';
					setTimeout(function () {
						item.meta.url = url
					}, 200);
				}
			})
		},
		clearIframeList(state) {
			state.iframeList = []
		}
	},
	actions: {
		getInfo() {
			return new Promise((resolve, reject) => {
				this.$API.auth.getUserInfo.get().then(response => {
					const {data} = response
					if (!data) {
						reject('登录信息已失效,请重新登陆!')
					}
					// 设置用户信息
					data.data.role = [
						"SA",
						"admin",
						"Auditor"
					]
					data.data.dashboard = "0"
					this.$TOOL.data.set("USER_INFO", data.data)
					resolve(data)
				}).catch(error => {
					reject(error)
				})
			})
		}
	}
}
